* Youth-Parent Socialization Panel Study setup and analysis for: 
* Unions, Class Identification and Policy Attitudes
* Date: 03/31/22


use "YPSS_04037.dta", clear


*******************************************************************************
***** Data setup.
*******************************************************************************


recode V751 (1 3 = 0) (2 4 = 1) (0 5 6 7 . = .), gen(workcls_1)

recode V2324 (1 3 = 0) (2 4 = 1) (7 . = .), gen(workcls_2)

gen workcls_3 = 0 if V6505 != .
replace workcls_3 = 1 if V6506 == 2 | V6507 == 2


recode V728 (1 = 1) (5 = 0), gen(union_1)

recode V2238 (1 = 1) (5 0 = 0), gen(union_2)

recode V6300 (1 = 1) (5 = 0), gen(union_3)


* A lot of missing data for occupation.
codebook V687 V2101 V6233


* Education.
gen edu_1 = 0
replace edu_1 = 1 if (V652==1) | (V653==1) | (V654==1)
replace edu_1 = 2 if (V652==2) | (V653==2) | (V654==2)
replace edu_1 = 3 if (V652==3) | (V653==3) | (V654==3)
replace edu_1 = 3 if (V652==4) | (V653==4) | (V654==4)
replace edu_1 = 3 if (V652==5) | (V653==5) | (V654==5)
replace edu_1 = 3 if (V652==6) | (V653==6) | (V654==6)
replace edu_1 = 3 if (V652==7) | (V653==7) | (V654==7)

gen edu_2 = edu_1
replace edu_2 = 1 if (V2026==1) | (V2027==1) & edu_1 < 1
replace edu_2 = 2 if (V2026==2) | (V2027==2) & edu_1 < 2
replace edu_2 = 3 if (V2026==3) | (V2027==3) & edu_1 < 3
replace edu_2 = 3 if (V2026==4) | (V2027==4) & edu_1 < 3
replace edu_2 = 3 if (V2026==5) | (V2027==5) & edu_1 < 3
replace edu_2 = 3 if (V2026==6) | (V2027==6) & edu_1 < 3
replace edu_2 = 3 if (V2026==7) | (V2027==7) & edu_1 < 3

gen edu_3 = edu_2
replace edu_3 = 1 if (V6225==1) | (V6226==1) | (V6227==1) & edu_2 < 1
replace edu_3 = 2 if (V6225==2) | (V6226==2) | (V6227==2) & edu_2 < 2
replace edu_3 = 3 if (V6225==3) | (V6226==3) | (V6227==3) & edu_2 < 3
replace edu_3 = 3 if (V6225==4) | (V6226==4) | (V6227==4) & edu_2 < 3
replace edu_3 = 3 if (V6225==5) | (V6226==5) | (V6227==5) & edu_2 < 3
replace edu_3 = 3 if (V6225==6) | (V6226==6) | (V6227==6) & edu_2 < 3
replace edu_3 = 3 if (V6225==7) | (V6226==7) | (V6227==7) & edu_2 < 3


* Income.
codebook V744 V2318 V6401 

gen inc_72 = V744

gen inc_81 = V2318 if V2317 == 2
replace inc_81 = V2319 if V2317 == 1
replace inc_81 = . if inc_81 == 97

gen inc_96 = V6401 if V6400 == 2
replace inc_96 = V6403 if V6400 == 1


* Need to make income comparable across waves.
* Use midpoint for each income category, then adjust to 
* 1996 dollars using CPI.
numlabel V744 V2318 V6401, add

replace 	inc_72 =	0	 if inc_72 ==	1
replace 	inc_72 =	500	 if inc_72 ==	2
replace 	inc_72 =	1500	 if inc_72 ==	3
replace 	inc_72 =	2500	 if inc_72 ==	4
replace 	inc_72 =	3500	 if inc_72 ==	5
replace 	inc_72 =	4500	 if inc_72 ==	6
replace 	inc_72 =	5500	 if inc_72 ==	7
replace 	inc_72 =	6500	 if inc_72 ==	8
replace 	inc_72 =	7500	 if inc_72 ==	9
replace 	inc_72 =	8500	 if inc_72 ==	10
replace 	inc_72 =	9500	 if inc_72 ==	11
replace 	inc_72 =	10500	 if inc_72 ==	12
replace 	inc_72 =	11500	 if inc_72 ==	13
replace 	inc_72 =	13500	 if inc_72 ==	14
replace 	inc_72 =	17500	 if inc_72 ==	15
replace 	inc_72 =	22500	 if inc_72 ==	16
replace 	inc_72 =	30000	 if inc_72 ==	17
replace 	inc_72 =	40000	 if inc_72 ==	18
			
replace 	inc_81 =	1000	 if inc_81 ==	1
replace 	inc_81 =	3000	 if inc_81 ==	2
replace 	inc_81 =	5000	 if inc_81 ==	3
replace 	inc_81 =	7000	 if inc_81 ==	4
replace 	inc_81 =	9000	 if inc_81 ==	5
replace 	inc_81 =	11000	 if inc_81 ==	6
replace 	inc_81 =	13000	 if inc_81 ==	7
replace 	inc_81 =	15000	 if inc_81 ==	8
replace 	inc_81 =	17000	 if inc_81 ==	9
replace 	inc_81 =	19500	 if inc_81 ==	10
replace 	inc_81 =	22500	 if inc_81 ==	11
replace 	inc_81 =	25500	 if inc_81 ==	12
replace 	inc_81 =	28500	 if inc_81 ==	13
replace 	inc_81 =	31500	 if inc_81 ==	14
replace 	inc_81 =	34500	 if inc_81 ==	15
replace 	inc_81 =	38000	 if inc_81 ==	16
replace 	inc_81 =	42500	 if inc_81 ==	17
replace 	inc_81 =	47500	 if inc_81 ==	18
replace 	inc_81 =	55000	 if inc_81 ==	19
replace 	inc_81 =	65000	 if inc_81 ==	20
replace 	inc_81 =	75000	 if inc_81 ==	21
replace 	inc_81 =	85000	 if inc_81 ==	22

replace 	inc_96 =	7500	 if inc_96 ==	3
replace 	inc_96 =	12000	 if inc_96 ==	4
replace 	inc_96 =	16000	 if inc_96 ==	5
replace 	inc_96 =	20000	 if inc_96 ==	6
replace 	inc_96 =	24000	 if inc_96 ==	7
replace 	inc_96 =	28000	 if inc_96 ==	8
replace 	inc_96 =	32500	 if inc_96 ==	9
replace 	inc_96 =	37500	 if inc_96 ==	10
replace 	inc_96 =	42500	 if inc_96 ==	11
replace 	inc_96 =	47500	 if inc_96 ==	12
replace 	inc_96 =	55000	 if inc_96 ==	13
replace 	inc_96 =	65000	 if inc_96 ==	14
replace 	inc_96 =	75000	 if inc_96 ==	15
replace 	inc_96 =	85000	 if inc_96 ==	16
replace 	inc_96 =	95000	 if inc_96 ==	17
replace 	inc_96 =	105000	 if inc_96 ==	18
replace 	inc_96 =	115000	 if inc_96 ==	19
replace 	inc_96 =	125000	 if inc_96 ==	20
replace 	inc_96 =	135000	 if inc_96 ==	21
replace 	inc_96 =	145000	 if inc_96 ==	22
replace 	inc_96 =	155000	 if inc_96 ==	23


* CPI 1972 = 41.8
* CPI 1981 = 90.9
* CPI 1996 = 156.9
* For 1972: 156.9 / 41.8 = 3.754
* For 1981: 156.9 / 90.9 = 1.726

gen inc_1 = (inc_72 * 3.754) / 1000
gen inc_2 = (inc_81 * 1.726) / 1000
gen inc_3 = inc_96 / 1000


* Ideology.
codebook V380 V1304 V5300 

gen ideo_1 = V380
replace ideo_1 = 4 if V380 == .

gen ideo_2 = V1304
replace ideo_2 = 4 if V1304 == .

gen ideo_3 = V5300
replace ideo_3 = 4 if V5300 == .


* Gender.
recode V2325 (1 = 0 "Male") (2 = 1 "Female"), gen(female_1)
gen female_2 = female_1
gen female_3 = female_1

* Race (by observation).
recode V2326 (1 = 1 "White") (2 3 = 0 "Other"), gen(white_1)
gen white_2 = white_1
gen white_3 = white_1

* Work status.
recode V684 (1 = 1) (2 3 4 7 8 = 0), gen(working_1)
recode V2038 (1 = 1) (2 4 6 7 8 = 0), gen(working_2)
recode V6232 (10 = 1) (13/90 = 0), gen(working_3)


*******************************************************************************
***** Analysis.
*******************************************************************************


* Percentage working class vs. middle class in each wave.
estpost tab workcls_1 if !missing(workcls_1, workcls_2, workcls_3)
estimates store tabwc1
estpost tab workcls_2 if !missing(workcls_1, workcls_2, workcls_3)
estimates store tabwc2
estpost tab workcls_3 if !missing(workcls_1, workcls_2, workcls_3)
estimates store tabwc3

*** TABLE A8. ***
esttab tabwc1 tabwc2 tabwc3 using "Table_A8.tex" , replace style(tex) cell(pct(fmt(1)) b(fmt(0) par)) nonumber collabels(none) mtitle("Wave 1973" "Wave 1982" "Wave 1997") varlabels(0 "Middle class" 1 "Working class") noobs substitute(_ \_ # X < $<$ + $^+$ \hline\hline \hline) title(Subjective Class Identification by Wave in the Youth-Parent Socialization Panel Study\label{tab:desc.subcls.wave})


* How much change in working class ID and union membership?
egen w12diff = diff(workcls_1 workcls_2) if !mi(workcls_1, workcls_2)
egen u12diff = diff(union_1 union_2) if !mi(union_1, union_2)

egen w23diff = diff(workcls_2 workcls_3) if !mi(workcls_2, workcls_3)
egen u23diff = diff(union_2 union_3) if !mi(union_2, union_3)

sum w12diff u12diff w23diff u23diff



* Create new frame for posting results.
frame create prfd fd ll ul str30 mod


*** Two wave models.
* Wave 1973 to 1982
logit workcls_2 workcls_1 union_1 working_1 edu_1 inc_1 ideo_1 female_1 white_1 
estimates store m_12
margins , at((min) union) at((max) union) post
lincom [2._at] - [1._at] 
frame post prfd (`r(estimate)') (`r(lb)') (`r(ub)') ("Waves 1973-1982")

logit union_2 union_1 workcls_1 working_1 edu_1 inc_1 ideo_1 female_1 white_1 
estimates store m_rev12


* Wave 1982 to 1997
logit workcls_3 workcls_2 union_2 working_2 edu_2 inc_2 ideo_2 female_2 white_2 
estimates store m_23
margins , at((min) union) at((max) union) post
lincom [2._at] - [1._at]
frame post prfd (`r(estimate)') (`r(lb)') (`r(ub)') ("Waves 1982-1997")


logit union_3 union_2 workcls_2 working_2 edu_2 inc_2 ideo_2 female_2 white_2 
estimates store m_rev23




* Estimate equations simultaneously. Cross-lagged panel model.

gsem ///
(workcls_2 <- workcls_1 union_1 working_1 edu_1 inc_1 ideo_1 female_1 white_1, logit) ///
(union_2 <- union_1 workcls_1 working_1 edu_1 inc_1 ideo_1 female_1 white_1, logit) ///
(workcls_3 <- workcls_2 union_2 working_2 edu_2 inc_2 ideo_2 female_2 white_2, logit) ///
(union_3 <- union_2 workcls_2 working_2 edu_2 inc_2 ideo_2 female_2 white_2, logit) , 

estimates store m_gsem



******************************************************************************
*** Reshape data to long for three wave models.
drop inc_72 inc_81 inc_96
gen id = V5
reshape long workcls_ union_ edu_ inc_ ideo_ female_ white_ working_ , i(id) j(wave) 


* Create within- and between-cluster versions of variables.

local varlist "workcls_ union_ edu_ inc_ ideo_ female_ white_ working_"

foreach v of local varlist {
	bysort id: egen `v'bw = mean(`v')
	gen `v'wi = `v' - `v'bw
}


xtset id wave


* All 3 waves.
* Working class models.
xtlogit workcls_ l.workcls_ l(0/1).union_ l(0/1).edu_ l(0/1).inc_ l(0/1).working_ l(0/1).ideo_ female_ white_ , re 
estimates store m_123
margins , at((min) L.union) at((max) L.union) force post
lincom [2._at] - [1._at]
frame post prfd (`r(estimate)') (`r(lb)') (`r(ub)') ("Waves 1973-1982-1997")

xtlogit workcls_ l.workcls_ l(0/1).union_wi union_bw l(0/1).edu_wi edu_bw l(0/1).inc_wi inc_bw l(0/1).working_wi working_bw l(0/1).ideo_wi ideo_bw female_ white_ , re 
estimates store m_123w
margins , at((min) L.union) at((max) L.union) force post
lincom [2._at] - [1._at]
frame post prfd (`r(estimate)') (`r(lb)') (`r(ub)') ("Waves 1973-1982-1997 (centered)")

* Union models.
xtlogit union_ l.union_ l(0/1).workcls_ l(0/1).edu_ l(0/1).inc_ l(0/1).working_ l(0/1).ideo_ female_ white_ , re 
estimates store m_rev123

xtlogit union_ l.union_ l(0/1).workcls_wi workcls_bw l(0/1).edu_wi edu_bw l(0/1).inc_wi inc_bw l(0/1).working_wi working_bw l(0/1).ideo_wi ideo_bw female_ white_ , re 
estimates store m_rev123w


* TABLE 4.
* Saved first difference effects.
frame prfd: format %9.3f fd ll ul
frame prfd: list

